package Package.FunctionalInterfaces.PredicateInterface;

import java.util.function.Predicate;

public class PredicateInterface {
    public static void PredicateInterface (){
//        Predicate接口
//Predicate接口通常用于判断参数是否满足指定的条件
//常用方法
//        boolean test(T t) 对给定的参数进行判断(判断逻辑由Lambda表达式实现)，返回
//一个布尔值
//default Predicate negate() 返回一个逻辑的否定，对应逻辑非
//default Predicate and(Predicate other) 返回一个组合判断，对应短路与
//default Predicate or(Predicate other) 返回一个组合判断，对应短路或
        boolean b1=CheckString("ChangCun",s-> s.length()>2);
        System.out.println(b1);
        System.out.println("------------------------------");
        boolean b2=CheckString("ChangCun",s-> s.length()>2);
        System.out.println(b2);
        System.out.println("----------------------------------");
        boolean b3=CheckString1("YnagYinTao",s->{
            System.out.println(s);
            return  s.length()>5;
        },s->{
            System.out.println(s);
            return  s.length()<3;
        });
        System.out.println(b3);
        System.out.println("------------------------------------------");
        boolean b4=CheckString1("YangYinTao",s->{
            System.out.println(s);
            return  s.length()>5;
        });
        System.out.println(b4);
    }
    private static boolean CheckString(String s, Predicate<String> pre){
        return pre.test(s);
    }
    private static boolean CheckString(String s, Predicate<String> pre1, Predicate<String> pre2){
        return pre1.or(pre2).test(s);
    }
    private static boolean CheckString1(String s, Predicate<String> pre1, Predicate<String> pre2){
        return pre1.and(pre2).test(s);
    }
    private static boolean CheckString1(String s, Predicate<String> pre1){
        return pre1.negate().test(s);
    }
}
